package com.css.influence.entity.MessageLog.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.css.influence.entity.MessageLog.entity.MessageLog;
import com.css.influence.entity.MessageLog.mapper.MessageLogMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.UUID;

/**
 * @author Dbj
 * @date 2024年09月11日  17:28
 */
@Service
public class MessageLogService extends ServiceImpl<MessageLogMapper, MessageLog> {

    /**
     *       exchange  交换机
     *       routingKey 路由key
     *       status 发送结果  成功/失败
     *       content 消息内容
     *       desc 功能描述
     */
    @Transactional(rollbackFor = Exception.class)
    public void createAndSaveMessageLog(String exchange, String routingKey, String status, LinkedHashMap<String, Object> content, String desc, String classType){
        MessageLog log = MessageLog.builder().id(UUID.randomUUID().toString().replace("-",""))
                .exchange(exchange).routingKey(routingKey).sendTime(DateUtil.date()).status(status)
                .content(content).desc(desc).classType(classType).build();
        save(log);
    }
}
